﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using SocketLibrary;

namespace SocketServer
{
    public partial class FrmMain : Form
    {
        TcpSvrManager t_tcp_mgr = new TcpSvrManager(8000, "Data Source=rfid204;User ID=rfid;Password=rfid;");

        public FrmMain()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            
            t_tcp_mgr.CommandReceived += new CommandReceivedEventHandler(CommandReceivedData);
        }

        /// <summary>
        /// 接受到数据，处理之后回送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandReceivedData(object sender, CommandEventArgs e)
        {
            switch (e.CmdInfo.CommandType)
            {
                case SocketLibrary.CommandType.ExcuteSQL:
                case SocketLibrary.CommandType.QueryData:
                    txt_info.AppendText(e.CmdInfo.ToString());
                    txt_info.AppendText("\r\n");

                    CommandInfo t_cmd = new CommandInfo();
                    t_cmd.SenderIP = e.CmdInfo.SenderIP;
                    t_cmd.CommandType = e.CmdInfo.CommandType;
                    t_cmd.SetSendData(e.CmdInfo.ToString() + "  " + DateTime.Now.ToString());

                    //t_tcp_mgr.SendCommand(t_cmd);
                  
                    break;
            }

        }
    }
}